package com.cip.master.action;

import java.util.List;
import java.util.Locale;

import com.cip.admin.model.User;
import com.cip.common.util.SecurityUtil;
import com.cip.master.model.Holiday;
import com.cip.master.service.HolidayService;
import com.cip.webapp.action.BaseAction;
import java.text.SimpleDateFormat;

import com.cip.master.model.Academic;
import com.cip.master.service.AcademicService;

public class HolidayAction extends BaseAction {
	
	private Holiday holiday;
    private List<Holiday> holidayList;
    private HolidayService  holidayService;
	private AcademicService  academicService;
	List<Academic>  academicList;
	private String academicYear;
    
    public String saveOrUpdateHoliday()throws Exception {
    	
    	User user = SecurityUtil.getThreadLocalUser().get();
		Academic academic = academicService.getAcademicById(Integer.parseInt(getAcademicYear()));
		holiday.setAcademic(academic);
		holiday.setTenantId(user.getTenantId());
		holidayService.saveOrUpdateHoliday(holiday);
		saveMessage(getText("holiday.added"));
		return SUCCESS;
    }
    
  	public String showHolidayList() throws Exception {
  		Locale locale = getRequest().getLocale();
		String holidayString = holidayService.getHolidayGridList(locale,getRequest());
				
		getRequest().setAttribute("holidayGridString", holidayString);
		
//		setHolidayList(holidayService.getAllHolidayList());
		return SUCCESS;
	}

	public String showEditHoliday() {
		try {
			setHoliday(holidayService.getHolidayById(holiday.getId()));
			setAcademicList(academicService.getAllAcademicList());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public String showHolidayForm() throws Exception{
		setAcademicList(academicService.getAllAcademicList());
		setHoliday(new Holiday());
		return SUCCESS;
	}
	public HolidayService getHolidayService() {
		return holidayService;
	}

	public void setHolidayService(HolidayService holidayService) {
		this.holidayService = holidayService;
	}

	public Holiday getHoliday() {
		return holiday;
	}

	public void setHoliday(Holiday holiday) {
		this.holiday = holiday;
	}

	public List<Holiday> getHolidayList() {
		return holidayList;
	}

	public void setHolidayList(List<Holiday> holidayList) {
		this.holidayList = holidayList;
	}

	/**
	 * @return the academicService
	 */
	public AcademicService getAcademicService() {
		return academicService;
	}

	/**
	 * @param academicService the academicService to set
	 */
	public void setAcademicService(AcademicService academicService) {
		this.academicService = academicService;
	}

	public List<Academic> getAcademicList() {
		return academicList;
	}

	public void setAcademicList(List<Academic> academicList) {
		this.academicList = academicList;
	}

	public String getAcademicYear() {
		return academicYear;
	}

	public void setAcademicYear(String academicYear) {
		this.academicYear = academicYear;
	}    
}
